<template>
    <a-form ref='formRef' :label-col='{span : 5}' :model='formData'>
        <a-form-item style='display:none' name='id'>
            <a-input type='hidden' v-model:value='formData.id' />
        </a-form-item>
        <a-form-item label='名称' name='name' :rules="[{required : true, message : '请填写名称'}]">
            <a-input type='text' v-model:value='formData.name' />
        </a-form-item>
        <a-form-item label='appId' name='appId' :rules="[{required : true, message : '请填写appId'}]">
            <a-input type='text' v-model:value='formData.appId' />
        </a-form-item>
        <a-form-item label='appSecret' name='appSecret' :rules="[{required : true, message : '请填写appSecret'}]">
            <a-input type='text' v-model:value='formData.appSecret' />
        </a-form-item>
        <a-form-item label='接口' name='url' :rules="[{required : true, message : '请填写接口'}]">
            <a-input type='text' v-model:value='formData.url' />
        </a-form-item>
        <a-form-item label='启用' name='enable'>
            <a-switch v-model:checked='formData.enable' checked-children='启用' un-checked-children='禁用'/>
        </a-form-item>
    </a-form>
</template>

<script lang="ts" setup>
    import { saveApi } from '@/api/MessageServer';
        import { UploadOutlined } from '@ant-design/icons-vue';
        import { ref } from 'vue';


    const props = defineProps<{
        row? : any;
        category? : number
    }>()

    const fileList = ref<any[]>([])

    const formRef = ref()

    
    const formData = ref({
        id : 0,
        name : '',
        appId : '',
        appSecret : '',
        url : '',
        enable : true
    })

    if(props.row) {
        for(let k in props.row) {
            if(k in formData.value) {
                formData.value[k] = props.row[k]
            }
        }

        
    }

    async function submit() {
        let params  = await formRef.value.validate()
       
        return saveApi(params)
    }


    defineExpose({
        submit
    })
</script>